<template>
  <a-modal v-model="visible" title="编辑计划" @ok="handleOk" width="75%">
    <a-form-model
      ref="rulesForm"
      :model="form"
      :rules="rules"
      :labelCol="{ lg: { span: 5 }, sm: { span: 7 } }"
      :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
    >
      <a-form-model-item label="品牌" prop="brand">
        <a-select v-model="form.brand" placeholder="请选择" :getPopupContainer="triggerNode => triggerNode.parentNode">
          <a-select-option v-for="(item, index) in brandList" :key="index" :value="item.code">{{ item.name }}</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="季节" prop="season">
        <a-select v-model="form.season" placeholder="请选择" :getPopupContainer="triggerNode => triggerNode.parentNode">
          <a-select-option value="1">春</a-select-option>
          <a-select-option value="2">夏</a-select-option>
          <a-select-option value="3">秋</a-select-option>
          <a-select-option value="4">冬</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="年份" prop="year" required>
        <a-date-picker
          mode="year"
          style="width:100%;"
          placeholder="请选择年份"
          format="YYYY"
          v-model="form.year"
          :open="yearShowOne"
          @change="handChange"
          @openChange="openChangeOne"
          @panelChange="panelChangeOne"
        />
      </a-form-model-item>
      <!-- <a-form-model-item label="预计入库时间" prop="preEntryTime">
        <a-date-picker allowClear v-model="form.preEntryTime" style="width:100%;" @change="onChangeEntryTime" />
      </a-form-model-item>
      <a-form-model-item label="预计预分开始时间" prop="preAssignedBeginTime">
        <a-date-picker allowClear v-model="form.preAssignedBeginTime" style="width:100%;" @change="onChangeBeginTime" />
      </a-form-model-item> -->
    </a-form-model>
  </a-modal>
</template>
<script>
import moment from 'moment'
import { saveProductPreAssigned, queryProductPreAssignedById } from '@/api/goods/preAssigned'
export default {
  props: ['brandList'],
  data() {
    return {
      visible: false,
      yearShowOne: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form: {
        brand: '',
        season: '',
        year: null
        // preEntryTime: '',
        // preAssignedBeginTime: ''
      },
      rules: {
        brand: [{ required: true, message: '请选择品牌' }],
        season: [{ required: true, message: '请选择季节' }],
        year: [{ required: true, message: '请选择年份', trigger: 'change' }]
        // preEntryTime: [{ required: true, message: '请选择预计入库时间' }],
        // preAssignedBeginTime: [{ required: true, message: '预计预分开始时间' }]
      },
      editRecord: {}
    }
  },

  methods: {
    show(record) {
      if (record) {
        this.form = record
      } else {
        this.form = {
          brand: '',
          season: '',
          year: null
          // preEntryTime: '',
          // preAssignedBeginTime: ''
        }
      }

      this.visible = true
    },
    handChange() {
      // this.form.year = null
    },
    // 弹出日历和关闭日历的回调
    openChangeOne(status) {
      this.yearShowOne = status
    },
    // 得到年份选择器的值
    panelChangeOne(value) {
      // console.log(value)
      this.form.year = moment(value).format('YYYY')
      this.yearShowOne = false
    },
    onChangeEntryTime(date, dateString) {
      // this.form.preEntryTime = dateString
      console.log(this.form)
    },
    onChangeBeginTime(date, dateString) {
      // this.form.preAssignedBeginTime = dateString
      console.log(this.form)
    },
    // 编辑确认
    handleOk() {
      this.$refs.rulesForm.validate(valid => {
        if (valid) {
          // console.log(this.form)
          let params = {
            requestData: this.form
          }
          saveProductPreAssigned(params).then(res => {
            if (res.code == 0) {
              this.$message.success('编辑成功！')
              this.visible = false
              this.$emit('updateTable')
            } else {
              this.$message.warning(res.msg)
            }
          })
        } else {
        }
      })
    }
  }
}
</script>
